﻿using System.Data;
using System.Collections.Generic;

namespace CRMSystemV2.BLL
{
    public class User
    {
        private static readonly dynamic Instance = DALFactory.DataAccess.CreateInstance("User");
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns>成功返回空消息，否则返回错误信息</returns>
        public string Login(string username, string password)
        {
            return Instance.Login(username, password);
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="username"></param>
        /// <param name="oldpassword"></param>
        /// <param name="newpassword"></param>
        /// <returns></returns>
        public string ChangePassword(string username, string oldpassword, string newpassword)
        {
            return Instance.ChangePassword(username, oldpassword, newpassword);
        }
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public string ResetPassword(string id, string password = "123456")
        {
            return Instance.ResetPassword(id, password);
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public string Insert(CRMSystemV2.Model.User user)
        {
            return Instance.Insert(user);
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string Delete(string ids)
        {
            return Instance.Delete(ids);
        }        
        /// <summary>
        /// 修改用户资料
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public string Update(CRMSystemV2.Model.User user)
        {
            return Instance.Update(user);
        }
        /// <summary>
        /// 查看用户详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public CRMSystemV2.Model.User GetUser(string userId)
        {
            return Instance.GetModel(userId);
        }
        /// <summary>
        /// 分页获取列表
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="RowCount"></param>
        /// <param name="PageCount"></param>
        /// <returns></returns>
        public DataTable GetPageView(int pageSize, int pageIndex, out int RowCount, out int PageCount, Dictionary<string, string> keyWords, string orderField, string orderDirection)
        {
            object result = Instance.GetPageView(pageSize, pageIndex,keyWords, orderField, orderDirection);
            RowCount = Instance.GetValue("RowCount");
            PageCount = Instance.GetValue("PageCount");
            return result as DataTable;
        }
        /// <summary>
        /// 获取导出数据表
        /// </summary>
        /// <param name="topCount"></param>
        /// <param name="orderField"></param>
        /// <param name="orderDirection"></param>
        /// <returns></returns>
        public DataTable GetExportTable(int topCount, Dictionary<string, string> keyWords, string orderField, string orderDirection)
        {
            return Instance.GetExportTable(topCount,keyWords,orderField, orderDirection);
        }
    }
}
